home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / Apple Script / OSAX / Finder Scripting Toolkit v1.0 / fwin coercion osax / long2fwin.c < prev    next >
Text File  |  1993-07-20  |  2KB  |  77 lines

  1. /*
  2.  
  3.         F W I N   C O E R C I O N   O S A X
  4.         
  5.         Version 1.0
  6.         Freeware by Daniel Ranson
  7.         
  8.         This osax performs coercions to the FinderWindow (fwin) record
  9.         type used by Finder events.
  10.         
  11.         There are actually three osax. This one converts integers, as a
  12.         special way to refer to the About and Clipboard windows.
  13.         The possible values are :
  14.             1 : about window
  15.             2 : clipboard window
  16.  
  17. */
  18.  
  19. #include <Types.h>
  20. #include <Memory.h>
  21. #include <Aliases.h>
  22. #include <AppleEvents.h>
  23. #include <AERegistry.h>
  24.  
  25. struct FinderWindow{
  26.     long        windowType;
  27.     DescType    aliasType;
  28.     long        aliasLength;
  29.     AliasRecord    alias;
  30. };
  31.  
  32. typedef struct FinderWindow FinderWindow;
  33.  
  34. pascal OSErr LONG2FWIN(    DescType    fromType,
  35.                         Ptr            dataPtr,
  36.                         Size        dataSize,
  37.                         DescType    toType,
  38.                         long        refCon,
  39.                         AEDesc        *result)
  40. {
  41. #pragma unused(fromType, dataSize, toType, refCon)
  42.  
  43.     FinderWindow    **hFwin;
  44.     Size            sizH;
  45.     long            val;
  46.     OSErr            err;
  47.     
  48.     /* Get the integer value */
  49.     val = *(long*)dataPtr;
  50.     if (val == 1)
  51.         val = 'abot';
  52.     else if (val == 2)
  53.         val = 'clip';
  54.     else
  55.         return errAECoercionFail;
  56.     
  57.     /* Allocate the structure */
  58.     sizH = 16;
  59.     hFwin = (FinderWindow**)NewHandle(sizH);
  60.     if (hFwin == 0) return errAECoercionFail;
  61.     
  62.     /* Fill in fields */
  63.     (**hFwin).windowType = 0;
  64.     (**hFwin).aliasType = 'find';
  65.     (**hFwin).aliasLength = 4;
  66.     BlockMove((Ptr)(&val), &((**hFwin).alias), 4);
  67.     
  68.     /* Create the descriptor */
  69.     MoveHHi((Handle)hFwin);
  70.     HLock((Handle)hFwin);
  71.     err = AECreateDesc(typeFinderWindow, (Ptr)(*hFwin), sizH, result);
  72.     
  73.     /* Clean up */
  74.     DisposeHandle((Handle)hFwin);
  75.     return err;
  76. }
  77.